package it.traveldreamWeb.shared;

import it.traveldream.dto.ExcursionDTO;

import java.util.List;

import javax.faces.model.ListDataModel;

import org.primefaces.model.SelectableDataModel;

public class ExcursionDataModel extends ListDataModel<ExcursionDTO> implements SelectableDataModel<ExcursionDTO>{

	public ExcursionDataModel() {  
    }  
  
    public ExcursionDataModel(List<ExcursionDTO> data) {  
        super(data);  
    }

	@Override
	public ExcursionDTO getRowData(String rowKey) {
		
		@SuppressWarnings("unchecked")
		List<ExcursionDTO> exs = (List<ExcursionDTO>) this.getWrappedData();
		
		for (ExcursionDTO ex : exs){
			if (ex.getProductId().equals(Long.decode(rowKey)))
				return ex;
		}
		return null;
	}

	@Override
	public Object getRowKey(ExcursionDTO ex) {
		return ex.getProductId();
	} 
}
